$(function () {
    var schoolId   = addressUri.getParam('schoolId');
    var type       = addressUri.getParam('type');
    var userId     = addressUri.getParam('userId');
    var stuName    = $('#targetPanel-title',window.parent.document).text().split('-')[1];
    var schoolName =  unescape(addressUri.getParam('schoolName'));
    // console.log(schoolName);
    var width=$(window).width()/4.0;
    $('#gridView .row div').each(function () {
        $(this).attr('style','height:'+width+'px;');
    })
    // console.log(stuName);
    window.onresize = function(){
        var width=$(window).width()/4.0;
        $('#gridView .row div').each(function () {
            $(this).attr('style','height:'+width+'px;');
        })
    }

    $.ajax({  //权限验证
        url:baseUrl+'mobile/shortcut/getUserManage',
        type:'POST',
        dataType:'json',
        data:{type:type,userId:userId},
        async:false,
        success:function (data) {
            $.each(data,function (index,value) {
                var target = $($('#gridView .row div')[index]);
                var str    = '<a   module="'+value['module']+'"   class="easyui-linkbutton"  data-options="iconCls:\''+value['iconClass']+'\',size:\'large\',iconAlign:\'top\',plain:true" style="height:100%;width: 100%">'+value['name']+'</a>';
                target.append(str);
            });
            $.parser.parse($('#gridView'));
        },
        error:function (data) {
            console.log(data);
        }
    });

    window.top.bindBack(function () {
        var text = schoolName;
        if(type == 1){ //学生、
            text += '-学生列表';
        }else {  //教师
            text += '-教师列表';
        }
        $('#targetFrame',window.parent.document).attr('src',baseUrl+'mobile/shortcut/userList?schoolId='+schoolId+'&type='+type+'&schoolName='+escape(schoolName));
        window.parent.setTitle(text);
    });

    $('#gridView').on('click','.easyui-linkbutton',function () {
        var module = $(this).attr('module');
        var title  = $(this).find('.l-btn-text').text();
        if (module == 'returnBorrow'){
            window.top.swal({title:'确认归还？',text: '你确定要归还',type:'info',confirmButtonText:'确定'}).then(function () {
                $.ajax({
                    url: baseUrl+'mobile/shortcut/returnBorrow',
                    dataType:'json',
                    data:{userId:userId},
                    type:'post',
                    complete:function (XMLHttpRequest) {
                        var result = XMLHttpRequest.responseJSON || XMLHttpRequest.responseText;
                        if(typeof result === 'string'){
                            window.top.sendErrorMsg(result);
                        }
                        if(result.error){
                            window.top.sendErrorMsg(result.error);
                        }
                        if(result.code === 200){
                            window.top.sendSuccessMsg(result.msg);
                        }
                    }
                })
            },function () {
                return false
            });
            return false;
        }
        //绑定自己返回点击事件
        window.top.registerBack();

        //点击事件



        $('#targetFrame',window.parent.document).attr('src',baseUrl+'mobile/shortcut/'+module+'?userId='+userId);
        $('#targetPanel-title',window.parent.document).html(title);
        window.parent.goTarget(); //跳转
    });



});